home *** CD-ROM | disk | FTP | other *** search
- head 4.0;
- access;
- symbols;
- locks; strict;
- comment @ * @;
-
-
- 4.0
- date 93.03.01.19.59.00; author davy; state Exp;
- branches;
- next 3.6;
-
- 3.6
- date 93.02.24.17.44.45; author davy; state Exp;
- branches;
- next 3.5;
-
- 3.5
- date 93.01.15.19.33.39; author davy; state Exp;
- branches;
- next 3.4;
-
- 3.4
- date 93.01.15.14.34.33; author davy; state Exp;
- branches;
- next 3.3;
-
- 3.3
- date 93.01.14.15.51.16; author davy; state Exp;
- branches;
- next 3.2;
-
- 3.2
- date 93.01.13.20.18.17; author davy; state Exp;
- branches;
- next 3.1;
-
- 3.1
- date 93.01.13.13.03.01; author davy; state Exp;
- branches;
- next 3.0;
-
- 3.0
- date 91.01.23.08.23.14; author davy; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 90.12.04.08.25.22; author davy; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 90.12.04.08.11.40; author davy; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 90.08.17.15.47.32; author davy; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 88.11.29.11.20.47; author davy; state Released;
- branches;
- next ;
-
-
- desc
- @NFSWATCH - monitor Network File System traffic on the network.
- @
-
-
- 4.0
- log
- @NFSWATCH Version 4.0.
- @
- text
- @#ifndef lint
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.6 1993/02/24 17:44:45 davy Exp davy $";
- #endif
-
- #include "os.h"
-
- #ifdef USE_NIT
- /*
- * nit.c - routines for messing with the network interface tap.
- *
- * David A. Curry
- * Purdue University
- * Engineering Computer Network
- * 1285 Electrical Engineering Building
- * West Lafayette, IN 47907-1285
- * davy@@ecn.purdue.edu
- *
- * $Log: nit.c,v $
- * Revision 3.6 1993/02/24 17:44:45 davy
- * Added -auth mode, changes to -proc mode, -map option, -server option.
- *
- * Revision 3.5 1993/01/15 19:33:39 davy
- * Miscellaneous cleanups.
- *
- * Revision 3.4 1993/01/15 14:34:33 davy
- * Changed to handle the default network interface even if the loopback
- * was ifconfig'd first.
- *
- * Revision 3.3 1993/01/14 15:51:16 davy
- * Added FDDI code and device type calculation to NIT and SNOOP. The FDDI
- * stuff almost definitely won't work without modification on the SNOOP
- * side; it still needs to be tested on the NIT side.
- *
- * Revision 3.2 1993/01/13 20:18:17 davy
- * Put in OS-specific define scheme, and merged in Tim Hudson's code for
- * SGI systems (as yet untested).
- *
- * Revision 3.1 1993/01/13 13:03:01 davy
- * Fixed the SUNOS40 calculation, and also fixed to only use promiscuous
- * mode when needed.
- *
- * Revision 3.0 1991/01/23 08:23:14 davy
- * NFSWATCH Version 3.0.
- *
- * Revision 1.4 90/12/04 08:25:22 davy
- * Fixed to automatically define SUNOS40.
- *
- * Revision 1.3 90/12/04 08:11:40 davy
- * Changed ifdef for SunOS 4.0.x.
- *
- * Revision 1.2 90/08/17 15:47:32 davy
- * NFSWATCH Version 2.0.
- *
- * Revision 1.1 88/11/29 11:20:47 davy
- * NFSWATCH Release 1.0
- *
- */
- #include <sys/param.h>
- #include <sys/stropts.h>
- #include <sys/socket.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #include <sys/file.h>
- #include <net/if.h>
- #include <signal.h>
- #include <stdio.h>
-
- #include <net/nit_if.h>
- #include <net/nit_buf.h>
-
- #include "nfswatch.h"
- #include "externs.h"
-
- #if NOFILE <= 64
- #define SUNOS40 1
- #endif
-
- /*
- * setup_nit_dev - set up the network interface tap.
- */
- int
- setup_nit_dev(device)
- char **device;
- {
- int n, s, fd;
- u_int chunksz;
- u_long if_flags;
- char buf[BUFSIZ];
- struct ifconf ifc;
- struct strioctl si;
- struct timeval timeout;
- struct ifreq ifr, *ifrp;
-
- /*
- * If the interface device was not specified,
- * get the default one.
- */
- if (*device == NULL) {
- /*
- * Grab a socket.
- */
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- error("socket");
- finish(-1);
- }
-
- ifc.ifc_buf = buf;
- ifc.ifc_len = sizeof(buf);
-
- /*
- * See what devices we've got.
- */
- if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
- error("ioctl: SIOCGIFCONF");
- finish(-1);
- }
-
- /*
- * Take the first device we encounter.
- */
- ifrp = ifc.ifc_req;
- for (n = ifc.ifc_len/sizeof(struct ifreq); n > 0; n--,ifrp++) {
- /*
- * Skip the loopback interface.
- */
- if (strcmp(ifrp->ifr_name, "lo0") == 0)
- continue;
-
- *device = savestr(ifrp->ifr_name);
- break;
- }
-
- (void) close(s);
- }
-
- /*
- * We want the ethernet in promiscuous mode if we're looking
- * at nodes other than ourselves, and we want to know about
- * dropped packets.
- */
- if (allflag || dstflag)
- if_flags = NI_DROPS | NI_PROMISC | NI_TIMESTAMP;
- else
- if_flags = NI_DROPS | NI_TIMESTAMP;
-
- /*
- * Open the network interface tap.
- */
- if ((fd = open(NIT_DEV, O_RDONLY)) < 0) {
- error("nit: open");
- finish(-1);
- }
-
- /*
- * Arrange to get discrete messages.
- */
- if (ioctl(fd, I_SRDOPT, (char *) RMSGD) < 0) {
- error("ioctl: I_SRDOPT");
- finish(-1);
- }
-
- /*
- * Push and configure the nit buffering module.
- */
- if (ioctl(fd, I_PUSH, NIT_BUF) < 0) {
- error("ioctl: I_PUSH NIT_BUF");
- finish(-1);
- }
-
- /*
- * Set the read timeout.
- */
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
-
- si.ic_cmd = NIOCSTIME;
- si.ic_timout = INFTIM;
- si.ic_len = sizeof(timeout);
- si.ic_dp = (char *) &timeout;
-
- if (ioctl(fd, I_STR, (char *) &si) < 0) {
- error("ioctl: I_STR NIOCSTIME");
- finish(-1);
- }
-
- /*
- * Set the chunk size.
- */
- chunksz = NIT_CHUNKSIZE;
-
- si.ic_cmd = NIOCSCHUNK;
- si.ic_len = sizeof(chunksz);
- si.ic_dp = (char *) &chunksz;
-
- if (ioctl(fd, I_STR, (char *) &si) < 0) {
- error("ioctl: I_STR NIOCSCHUNK");
- finish(-1);
- }
-
- /*
- * Configure the network interface tap by binding it
- * to the underlying interface, setting the snapshot
- * length, and setting the flags.
- */
- (void) strncpy(ifr.ifr_name, *device, sizeof(ifr.ifr_name));
- ifr.ifr_name[sizeof(ifr.ifr_name)-1] = '\0';
-
- si.ic_cmd = NIOCBIND;
- si.ic_len = sizeof(ifr);
- si.ic_dp = (char *) 𝔦
-
- /*
- * If the bind fails, there's no such device.
- */
- if (ioctl(fd, I_STR, (char *) &si) < 0) {
- close(fd);
- return(-1);
- }
-
- /*
- * SNAP is buggy on SunOS 4.0.x
- */
- #ifndef SUNOS40
- si.ic_cmd = NIOCSSNAP;
- si.ic_len = sizeof(truncation);
- si.ic_dp = (char *) &truncation;
-
- if (ioctl(fd, I_STR, (char *) &si) < 0) {
- error("ioctl: I_STR NIOCSSNAP");
- finish(-1);
- }
- #endif
-
- si.ic_cmd = NIOCSFLAGS;
- si.ic_len = sizeof(if_flags);
- si.ic_dp = (char *) &if_flags;
-
- if (ioctl(fd, I_STR, (char *) &si) < 0) {
- error("ioctl: I_STR NIOCSFLAGS");
- finish(-1);
- }
-
- return(fd);
- }
-
- /*
- * flush_nit - flush data from the nit.
- */
- void
- flush_nit(fd)
- int fd;
- {
- if (ioctl(fd, I_FLUSH, (char *) FLUSHR) < 0) {
- error("ioctl: I_FLUSH");
- finish(-1);
- }
- }
-
- /*
- * nit_devtype - determine the type of device we're looking at.
- */
- int
- nit_devtype(device)
- char *device;
- {
- /*
- * This whole routine is a kludge. Ultrix does it the
- * right way; see pfilt.c.
- */
-
- if (strncmp(device, "le", 2) == 0 || strncmp(device, "ie", 2) == 0)
- return(DLT_EN10MB);
-
- if (strncmp(device, "fddi", 4) == 0)
- return(DLT_FDDI);
-
- fprintf(stderr, "Unknown device type: %s -- assuming ethernet.\n",
- device);
- return(DLT_EN10MB);
- }
- #endif /* USE_NIT */
- @
-
-
- 3.6
- log
- @Added -auth mode, changes to -proc mode, -map option, -server option.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.5 1993/01/15 19:33:39 davy Exp davy $";
- d19 3
- @
-
-
- 3.5
- log
- @Miscellaneous cleanups.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.4 1993/01/15 14:34:33 davy Exp davy $";
- d19 3
- d139 1
- a139 1
- if_flags = NI_DROPS | NI_PROMISC;
- d141 1
- a141 1
- if_flags = NI_DROPS;
- @
-
-
- 3.4
- log
- @Changed to handle the default network interface even if the loopback
- was ifconfig'd first.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.3 1993/01/14 15:51:16 davy Exp davy $";
- d12 5
- a16 4
- * SRI International
- * 333 Ravenswood Avenue
- * Menlo Park, CA 94025
- * davy@@erg.sri.com
- d19 4
- d70 1
- a70 1
- #endif /* NOFILE */
- d226 1
- a226 1
- #endif /* SUNOS40 */
- @
-
-
- 3.3
- log
- @Added FDDI code and device type calculation to NIT and SNOOP. The FDDI
- stuff almost definitely won't work without modification on the SNOOP
- side; it still needs to be tested on the NIT side.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.2 1993/01/13 20:18:17 davy Exp davy $";
- d18 5
- d74 1
- a74 1
- int s, fd;
- a75 1
- char *strdup();
- a77 1
- struct ifreq ifr;
- d81 1
- d100 1
- a100 1
- * See what device it's attached to.
- d107 15
- a121 1
- *device = strdup(ifc.ifc_req->ifr_name);
- @
-
-
- 3.2
- log
- @Put in OS-specific define scheme, and merged in Tim Hudson's code for
- SGI systems (as yet untested).
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.1 1993/01/13 13:03:01 davy Exp davy $";
- d18 4
- d228 23
- @
-
-
- 3.1
- log
- @Fixed the SUNOS40 calculation, and also fixed to only use promiscuous
- mode when needed.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/nit.c,v 3.0 1991/01/23 08:23:14 davy Exp davy $";
- d5 3
- a7 1
- #ifdef sun
- d18 4
- d225 1
- a225 1
- #endif /* sun */
- @
-
-
- 3.0
- log
- @NFSWATCH Version 3.0.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/system/nfswatch/RCS/nit.c,v 1.4 90/12/04 08:25:22 davy Exp Locker: davy $";
- d15 4
- a18 1
- * $Log: nit.c,v $
- d48 1
- a48 1
- #if NOFILE > 64
- d98 3
- a100 2
- * We want the ethernet in promiscuous mode, and
- * we want to know about dropped packets.
- d102 4
- a105 1
- if_flags = NI_DROPS | NI_PROMISC;
- @
-
-
- 1.4
- log
- @Fixed to automatically define SUNOS40.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/nfswatch/RCS/nit.c,v 1.3 90/12/04 08:11:40 davy Exp Locker: davy $";
- d13 1
- a13 1
- * davy@@itstd.sri.com
- d16 3
- d52 1
- a52 1
- void
- d54 1
- a54 1
- char *device;
- d56 1
- a56 1
- int s;
- d58 1
- d70 1
- a70 1
- if (device == NULL) {
- d90 1
- a90 1
- device = ifc.ifc_req->ifr_name;
- d103 1
- a103 1
- if ((if_fd = open(NIT_DEV, O_RDONLY)) < 0) {
- d111 1
- a111 1
- if (ioctl(if_fd, I_SRDOPT, (char *) RMSGD) < 0) {
- d119 1
- a119 1
- if (ioctl(if_fd, I_PUSH, NIT_BUF) < 0) {
- d135 1
- a135 1
- if (ioctl(if_fd, I_STR, (char *) &si) < 0) {
- d149 1
- a149 1
- if (ioctl(if_fd, I_STR, (char *) &si) < 0) {
- d159 1
- a159 1
- (void) strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
- d166 6
- a171 3
- if (ioctl(if_fd, I_STR, (char *) &si) < 0) {
- error("ioctl: I_STR NIOCBIND");
- finish(-1);
- d182 1
- a182 1
- if (ioctl(if_fd, I_STR, (char *) &si) < 0) {
- d192 1
- a192 1
- if (ioctl(if_fd, I_STR, (char *) &si) < 0) {
- d196 2
- d204 2
- a205 1
- flush_nit()
- d207 1
- a207 1
- if (ioctl(if_fd, I_FLUSH, (char *) FLUSHR) < 0) {
- @
-
-
- 1.3
- log
- @Changed ifdef for SunOS 4.0.x.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/nfswatch/RCS/nit.c,v 1.2 90/08/17 15:47:32 davy Exp Locker: davy $";
- d16 3
- d41 4
- @
-
-
- 1.2
- log
- @NFSWATCH Version 2.0.
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/system/nfswatch/RCS/nit.c,v 1.1 88/11/29 11:20:47 davy Released Locker: davy $";
- d16 3
- d161 1
- a161 1
- * SNAP is buggy on 4.0.3.
- d163 1
- a163 1
- #ifndef _NIT_PF_ /* this is a 4.0.3 but not 4.1 symbol */
- d172 1
- a172 1
- #endif /* _NIT_PF_ */
- @
-
-
- 1.1
- log
- @NFSWATCH Release 1.0
- @
- text
- @d2 1
- a2 1
- static char *RCSid = "$Header$";
- d5 1
- d10 4
- a13 5
- * Research Institute for Advanced Computer Science
- * Mail Stop 230-5
- * NASA Ames Research Center
- * Moffett Field, CA 94035
- * davy@@riacs.edu
- d15 4
- a18 1
- * $Log$
- d142 2
- a143 1
- * to the unerlying interface and setting the flags.
- d157 14
- d192 1
- @
-